import { defHttp } from '/@/utils/http/axios';
import { useMessage } from '/@/hooks/web/useMessage';

const { createConfirm } = useMessage();

enum Api {
  list = '/entrust/labWsupervise/list',
  save = '/entrust/labWsupervise/add',
  edit = '/entrust/labWsupervise/edit',
  deleteOne = '/entrust/labWsupervise/delete',
  deleteBatch = '/entrust/labWsupervise/deleteBatch',
  importExcel = '/entrust/labWsupervise/importExcel',
  cancelOneEnt = '/entrust/labWsupervise/cancelOneEnt',
  exportXls = '/entrust/labWsupervise/exportXls',
  labSortsList = '/items/labItems/queryByPid',
  labSampleList = '/entrust/labEntrust/queryLabSampleListByEntId',
  submitSupervise = '/entrust/labWsupervise/submitSupervise',
  getExperimentProjectsList = '/items/labItems/queryItemsByPid', // 获取实验数据
  getAduitSign = '/entrust/labEntrust/byIdsa', // 获取初审、复审人员签名
  auditPass = '/entrust/labWsupervise/auditSupervise',
  auditBack = '/entrust/labWsupervise/auditBack',
}

/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;

/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;

/**
 * 列表接口
 * @param params
 */
export const list = (params) => defHttp.get({ url: Api.list, params });

/**
 * 删除单个
 * @param params
 * @param handleSuccess
 */
export const deleteOne = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.deleteOne, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};

/**
 * 批量删除
 * @param params
 * @param handleSuccess
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    },
  });
};

/**
 * 保存或者更新
 * @param params
 * @param isUpdate
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params }, { isTransformResponse: false });
};

/**
 * 获取样品类型
 * @param params
 */
export const labSortsList = (params) => defHttp.get({ url: Api.labSortsList, params });

/**
 * 子表单信息
 * @param params
 */
export const labSampleList = (params) => defHttp.get({ url: Api.labSampleList, params });

/**
 * 提交监督抽查单
 * @param params
 * @param handleSuccess
 */
export const submitSupervise = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.submitSupervise, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};
/**
 * 获取实验项目数据
 */
export const getExperimentProjects = (params) => defHttp.get({ url: Api.getExperimentProjectsList, params }, { isTransformResponse: false });

/**
 * 获取初审、复审人员签名
 */
export const getAduitSign = (params) => defHttp.get({ url: Api.getAduitSign, params }, { isTransformResponse: false });

/**
 * 撤销发布单
 * 用delete能实现功能但不是很好  后续优化
 */
export const cancelOneEnt = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.cancelOneEnt, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};
/**
 * 初审/复审通过
 * @param params
 */
export const auditPass = (params) => {
  let url = Api.auditPass;
  return defHttp.post({ url: url, params });
};

/**
 * 初审/复审退回
 * @param params
 */
export const auditBack = (params) => {
  let url = Api.auditBack;
  return defHttp.post({ url: url, params });
};
